<template>
  <div class="box">
    <van-nav-bar
  title="登录"
  left-text="返回"
  left-arrow
  @click-left="onClickLeft"
/>
<van-form @submit="onSubmit" class="form">
  <van-field
    v-model="username"
    name="username"
    label="用户名"
    placeholder="用户名"
    :rules="[{ required: true, message: '请填写用户名' }]"
  />
  <van-field
    v-model="password"
    type="password"
    name="password"
    label="密码"
    placeholder="密码"
    :rules="[{ required: true, message: '请填写密码' }]"
  />
  <div style="margin: 16px;">
    <van-button round block type="info" native-type="submit">登录</van-button>
  </div>
</van-form>
  </div>
</template>

<script>
/*
 *@Date: 2023-04-01 01:12:06
 *@Description: 模块描述
*/
import{login} from '../../api/userAPI'
export default {
  name: '',
  data () {
    return {
      username: '',
      password: '',
    }
  },
  created () {},
  mounted () {},
  methods: {
    async onSubmit(values) {
      console.log('submit', values);
      const res = await login(values)
      console.log(res);
      localStorage.setItem('token',res.data.data.token)
      this.$router.push('/')
    },
    onClickLeft(){
      this.$router.push('user')
    }
  },
}
</script>

<style lang="less" scoped>
  .form{
    margin-top: 50px;
  }
</style>
